package com.joker.aigc.controller;


import com.joker.aigc.domain.dto.UserDto;
import com.joker.aigc.domain.dto.UserLoginDto;
import com.joker.aigc.domain.entity.R;
import com.joker.aigc.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RequiredArgsConstructor
@Slf4j
@Validated
@RestController
@RequestMapping("/login")
@Tag(name = "login", description = "用户登录")
public class LoginController {


    private final LoginService loginService;


    /**
     * 用户登录
     *
     * @param dto
     * @return
     */
    @PostMapping
    public R<String> login(@Valid @RequestBody UserLoginDto dto) {
        log.info("登录信息 -->{}", dto);
        return R.ok(loginService.login(dto));
    }

    /**
     *
     * @param userDto
     * @return
     */
    @PostMapping("/register")
    @Operation(summary = "注册用户信息")
    public R<String> register(@Valid @RequestBody UserDto userDto) {
        log.info("注册信息 -->{}", userDto);
        loginService.register(userDto);
        return R.ok("注册成功");
    }

}
